#include "coins.h"
#include <QTimer>
Coins::Coins(QString btnImag)
{
    loadPng(btnImag);
    timer1 = new QTimer(this);
    connect(timer1, &QTimer::timeout, [=](){
        QString str = QString(":/myres/Coin000%1").arg(min++);
        loadPng(str);
        if(min > max)
        {
            min = 1;
            timer1->stop();
        }
    });
    timer2 = new QTimer(this);
    connect(timer2, &QTimer::timeout, [=](){
        QString str = QString(":/myres/Coin000%1").arg(max--);
        loadPng(str);
        if(min > max)
        {
            max = 8;
            timer2->stop();
        }
    });
}

void Coins::loadPng(QString btnImag)
{
    QPixmap pix;
    if(!pix.load(btnImag))
    {
        return ;
    }
    setFixedSize(pix.width(), pix.height());
    setStyleSheet("QPushButton{border:0px;}");
    setIcon(pix);
    setIconSize(QSize(pix.width(), pix.height()));
}

void Coins::Flip()
{
    if(isGold)
    {
        isGold = !isGold;
        timer1->start(30);
    }
    else
    {
        isGold = !isGold;
        timer2->start(30);
    }
}

void Coins::mousePressEvent(QMouseEvent* ev)//胜利之后不能再点
{
    if(hasWon == true)
    {
        return;
    }
    return QPushButton::mousePressEvent(ev);
}
